import { publicThreeClass } from "./publicDeps";
import {
  AnimationMixer,
  AnimationAction,
  LoopOnce,
  DirectionalLight,
  AmbientLight,
  Mesh,
  Color,
  DoubleSide,
  MeshBasicMaterial,
  TextureLoader,
  MeshLambertMaterial,
  MeshPhongMaterial,
  Vector2,
} from "three";
import type { FBX } from "three/examples/jsm/loaders/FBXLoader";
import { FBXLoader } from "three/examples/jsm/loaders/FBXLoader";
import { cloneDeep } from "lodash-es";
import { gltfsList } from "@/node/gltfs";
const fbxLoader = new FBXLoader();

export class RenGLTFLoaderJiqi extends publicThreeClass {
  async init(): Promise<void> {
    let textureLoader = new TextureLoader();
    let texture1 = textureLoader.load("http://192.168.40.88:984/image/33.png");
    let material = new MeshLambertMaterial({ map: texture1, side: DoubleSide });
    let planeMaterial = new MeshBasicMaterial({ color: new Color("blue") });
    gltfsList.forEach(async (item) => {
      const { url, position,scale } = item;
      if (url.includes("FBX")) {
        const gltf = (await fbxLoader.loadAsync(
          url
        )) as FBX;
        gltf.position.set(...position);
        gltf.scale.set(...scale)
        gltf.traverse(function (child: any) {
          if (child.type === "Mesh") {
            child.material = material;
            child.castShadow = true; //阴影
            child.receiveShadow = true; //接受别人投的阴影
          }
        });
        this.add(gltf);
      } else {
      }
    });

   // this.deps.camera.position.z = 100;

   // this.addControl();
  }

  update(): void {
    this.mixer?.update(this.deps.clock.getDelta());
    this.orbitControl?.update();
  }

  dispose(): void {
    this.mixer.stopAllAction();
    this.mixer = null;
    this.reset();
  }
}
